<template>
	<view class="gt-tab">
		<view class="gt-tab-row">
			<view v-for="(row,key) in arrayList" :key="key" @click="changeSelected(key)" class="gt-tab-item"
				:class="selected == key ?'gt-tab-item-selected':''">
				<text class="iconfont" :class="row.icon"></text>
				<text>{{row.val}}</text>
			</view>
		</view>
		<view class="gt-tab-bottom-line"></view>
	</view>
</template>

<script>
	export default {
		name: 'gt-tab',
		data() {
			return {
				index: 0
			}
		},
		model: {
			prop: 'selected',
			event: 'change'
		},
		props: {
			list: {
				type: [Array,Object],
				default: function() {
					return []
				}
			},
			selected: {
				type: [Number, String],
				default: function() {
					return 0
				}
			}
		},
		computed: {
			arrayList() {
				var arr = [];
				for (let i in this.list) {
					let row = this.list[i];
					if (row.val) {
						arr.push({
							val: row.val,
							icon: row.icon || ''
						});
					}
				}
				return arr;
			}
		},
		created() {

		},
		methods: {
			changeSelected(e) {
				this.$emit('change', e)
			},
		}
	}
</script>

<style lang="scss">
	.gt-tab {}

	.gt-tab-bottom-line {
		border-bottom: #EEEEEE solid 1px;
		margin-top: -1px;
	}

	.gt-tab-row {
		display: -webkit-box;
		display: -moz-box;
		display: -ms-flexbox;
		display: -webkit-flex;
		display: flex;
		flex-flow: row wrap;
		-webkit-flex-flow: row wrap;
		-ms-flex-flow: row wrap;
		box-sizing: border-box;
	}

	.gt-tab-item {
		line-height: 38px;
		padding: 0 15px;
		cursor: pointer;
		border-bottom: 1px solid #eeeeee;
	}

	.gt-tab-card {
		.gt-tab-row {
			padding-left: 10px;
		}
		.gt-tab-item {
			border: 1px solid #eeeeee;
			background-color: #fafafa;
			color: #999999;
			margin-left: 5px;
			border-radius: 5px 5px 0 0;
			position: relative;
		}
		.gt-tab-item-selected {
			color: #409EFF;
			background-color: #ffffff;
			border-bottom: 1px solid #ffffff;
		}
	}

	.gt-tab-border-card {}

	.gt-tab-btn {
		.gt-tab-row {
		}
		.gt-tab-item {
			color: #666666;
			border: 1px solid #eeeeee;
			border-left: none;
			background-color: #fafafa;
			color: #999999;
			border-radius: none;
			position: relative;
		}
		.gt-tab-item:first-child {
			border-left: 1px solid #eeee;
			border-radius: 5px 0 0 5px;
		}
		.gt-tab-item:last-child {
			border-radius: 0 5px 5px 0;
		}
		.gt-tab-item-selected {
			color: #409EFF;
			background-color: #ffffff;
		}
		.gt-tab-bottom-line {
			display: none;
		}
	}

	.gt-tab-item-selected {
		color: #409EFF;
		background-color: #ffffff;
		border-bottom: 1px solid #409EFF;
	}

	.status-item {
		height: 45px;
		line-height: 45px;
		width: 120px;
		color: #727579;
		border-top-left-radius: 5px;
		border-top-right-radius: 5px;
		position: relative;
	}

	.selected-sign {
		color: #409EFF;
		border-bottom: 0px;
		box-sizing: border-box;
		box-shadow: 0px 0px 3px #BBBBBB;
	}

	.unselected {
		background-color: #F9F9F9;
	}

	.unselected:hover {
		background-color: #EEEEEE;
	}

	.statusNum {
		height: 17px;
		line-height: 17px;
		padding: 0px 5px;
		text-align: center;
		font-size: 12px;
		color: #FFFFFF;
		background-color: #fa5252;
		border-radius: 50px;
		position: absolute;
		top: -6.5px;
		right: 0px;
		z-index: 1;
	}
</style>
